package com.gilgamesh.mall.sdk.util;

import com.gilgamesh.mall.sdk.dto.ResponseDTO;

/**
 * @author yanm
 * @date 2021/1/13 15:50
 **/
public class ResponseUtil {

    public static <T> ResponseDTO<T> getResponse(T data){
        ResponseDTO<T> responseDTO = new ResponseDTO<>();
        if(data == null){
             responseDTO.setData(null);
             responseDTO.setMessage("error");
             responseDTO.setSuccess(Boolean.FALSE);
             responseDTO.setCode("1");
        }else{
            if(data instanceof String){
                if(StringUtil.isNotEmpty((String)data)){
                    responseDTO.setData(null);
                    responseDTO.setMessage("error");
                    responseDTO.setSuccess(Boolean.FALSE);
                    responseDTO.setCode("1");
                }
            }else{
                responseDTO.setData(data);
                responseDTO.setMessage("success");
                responseDTO.setSuccess(Boolean.TRUE);
                responseDTO.setCode("0");
            }
        }
        return responseDTO;
    }
}
